# @Time: 2023/1/26 14:30
# @Author: 张江南
# @File:
# @Project: 代码
import xlwings as xw

# 打开Excel程序，默认设置：程序可见，只打开不新建工作薄，屏幕更新关闭
app = xw.App(visible=False, add_book=False)
app.display_alerts = True  # 显示警报()
app.screen_updating = False  # 屏幕更新(应用中)
wb = ""
try:
    # 文件位置：filepath，打开test文档，然后保存，关闭，结束程序
    filepath = '../excel/csdn001.xlsx'
    wb = app.books.open(filepath)
    wb.sheets.add("sheet2")
    sht1 = wb.sheets['sheet1']
    info = wb.sheets['sheet1'].used_range
    nrows = info.last_cell.row
    print(nrows)
    # print(wb.sheets.count)
except Exception as e:
    print(e)
finally:
    wb.save()
    wb.close()
    app.quit()
    app.kill()
